home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / program / lgavb25.zip / VC.ZIP / VCVIEW.CPP < prev    next >
C/C++ Source or Header  |  1996-01-20  |  8KB  |  269 lines

  1. // vcview.cpp : implementation of the CVcView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "vc.h"
  6.  
  7. #include "vcdoc.h"
  8. #include "vcview.h"
  9.  
  10. #include "math.h"
  11.  
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CVcView
  19.  
  20. IMPLEMENT_DYNCREATE(CVcView, CFormView)
  21.  
  22. BEGIN_MESSAGE_MAP(CVcView, CFormView)
  23.     //{{AFX_MSG_MAP(CVcView)
  24.     ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  25.     ON_WM_DESTROY()
  26.     ON_WM_TIMER()
  27.     ON_VBXEVENT(VBN_CHANGE, IDC_LGAUGE1, OnChangeLgauge1)
  28.     ON_VBXEVENT(VBN_CHANGE, IDC_LGAUGE2, OnChangeLgauge2)
  29.     ON_VBXEVENT(VBN_CHANGE, IDC_LGAUGE3, OnChangeLgauge3)
  30.     ON_VBXEVENT(VBN_SLIDE, IDC_LGAUGE1, OnChangeLgauge1)
  31.     ON_VBXEVENT(VBN_SLIDE, IDC_LGAUGE2, OnChangeLgauge2)
  32.     ON_VBXEVENT(VBN_SLIDE, IDC_LGAUGE3, OnChangeLgauge3)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CVcView construction/destruction
  38.  
  39. CVcView::CVcView()
  40.     : CFormView(CVcView::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CVcView)
  43.     m_lgauge3 = NULL;
  44.     m_lgauge1 = NULL;
  45.     m_lgauge2 = NULL;
  46.     //}}AFX_DATA_INIT
  47.     // TODO: add construction code here
  48. }
  49.  
  50. CVcView::~CVcView()
  51. {
  52. }
  53.  
  54. void CVcView::DoDataExchange(CDataExchange* pDX)
  55. {
  56.     CFormView::DoDataExchange(pDX);
  57.     //{{AFX_DATA_MAP(CVcView)
  58.     DDX_VBControl(pDX, IDC_LGAUGE3, m_lgauge3);
  59.     DDX_VBControl(pDX, IDC_LGAUGE1, m_lgauge1);
  60.     DDX_VBControl(pDX, IDC_LGAUGE2, m_lgauge2);
  61.     //}}AFX_DATA_MAP
  62.     
  63.     SetTimer(1,55,NULL);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CVcView diagnostics
  68.  
  69. #ifdef _DEBUG
  70. void CVcView::AssertValid() const
  71. {
  72.     CFormView::AssertValid();
  73. }
  74.  
  75. void CVcView::Dump(CDumpContext& dc) const
  76. {
  77.     CFormView::Dump(dc);
  78. }
  79.  
  80. CVcDoc* CVcView::GetDocument() // non-debug version is inline
  81. {
  82.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVcDoc)));
  83.     return (CVcDoc*)m_pDocument;
  84. }
  85. #endif //_DEBUG
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CVcView message handlers
  89.  
  90.  
  91. void CVcView::OnButton1()
  92. {
  93. float value;
  94.  
  95.     //get value of pointer(0)
  96.     m_lgauge1->SetNumProperty("PointerID",0);
  97.     value = m_lgauge1->GetFloatProperty("PointerValue");
  98.     
  99.     //set value of pointer(1)
  100.     m_lgauge1->SetNumProperty("PointerID",1);
  101.     m_lgauge1->SetFloatProperty("PointerValue",value);
  102.     
  103.     //set value of pointer(2)
  104.     m_lgauge1->SetNumProperty("PointerID",2);
  105.     m_lgauge1->SetFloatProperty("PointerValue",value);
  106. }
  107.  
  108. void CVcView::OnDestroy()
  109. {
  110.     CFormView::OnDestroy();
  111.     
  112.     KillTimer(1);
  113.     
  114. }
  115.  
  116. void CVcView::OnTimer(UINT nIDEvent)
  117. {
  118. float max,min,value;
  119.     
  120.     //update thermometer example
  121.     //get value of pointer(0)
  122.     m_lgauge1->SetNumProperty("PointerID",0);
  123.     value = m_lgauge1->GetFloatProperty("PointerValue");
  124.     value = value + (float) 3.0*rand()/RAND_MAX - (float) 1.5;
  125.     m_lgauge1->SetFloatProperty("PointerValue",value);
  126.     value = m_lgauge1->GetFloatProperty("PointerValue");
  127.     
  128.     //change band level
  129.     m_lgauge1->SetNumProperty("BandID",1);
  130.     m_lgauge1->SetFloatProperty("BandStart",value);
  131.     
  132.     //check value of pointer(1)
  133.     m_lgauge1->SetNumProperty("PointerID",1);
  134.     min = m_lgauge1->GetFloatProperty("PointerValue");
  135.     if (value<min) {
  136.         m_lgauge1->SetFloatProperty("PointerValue",value);
  137.         }
  138.     
  139.     //check value of pointer(2)
  140.     m_lgauge1->SetNumProperty("PointerID",2);
  141.     max = m_lgauge1->GetFloatProperty("PointerValue");
  142.     if (value > max) {
  143.         m_lgauge1->SetFloatProperty("PointerValue",value);
  144.         }
  145.  
  146.  
  147.     CFormView::OnTimer(nIDEvent);
  148. }
  149.  
  150. void CVcView::OnChangeLgauge1(UINT, int, CWnd*, LPVOID)
  151. {
  152. float max,min,value;
  153.     
  154.     //get value of pointer(0)
  155.     m_lgauge1->SetNumProperty("PointerID",0);
  156.     value = m_lgauge1->GetFloatProperty("PointerValue");
  157.     
  158.     //change band level
  159.     m_lgauge1->SetNumProperty("BandID",1);
  160.     m_lgauge1->SetFloatProperty("BandStart",value);
  161.     
  162.     //check value of pointer(1)
  163.     m_lgauge1->SetNumProperty("PointerID",1);
  164.     min = m_lgauge1->GetFloatProperty("PointerValue");
  165.     if (value<min) {
  166.         m_lgauge1->SetFloatProperty("PointerValue",value);
  167.         }
  168.     
  169.     //check value of pointer(2)
  170.     m_lgauge1->SetNumProperty("PointerID",2);
  171.     max = m_lgauge1->GetFloatProperty("PointerValue");
  172.     if (value > max) {
  173.         m_lgauge1->SetFloatProperty("PointerValue",value);
  174.         }
  175.     
  176. }
  177.  
  178. void CVcView::OnChangeLgauge2(UINT, int, CWnd*, LPVOID)
  179. {
  180. int pointerid;
  181. float a,b;
  182.  
  183.     pointerid = (int) m_lgauge2->GetNumProperty("PointerID");
  184.     
  185.     switch (pointerid) {
  186.         case 0:
  187.             m_lgauge2->SetNumProperty("PointerID",0);
  188.             a = m_lgauge2->GetFloatProperty("PointerValue");
  189.             
  190.             m_lgauge2->SetNumProperty("PointerID",1);
  191.             b = m_lgauge2->GetFloatProperty("PointerValue");
  192.             
  193.             m_lgauge2->SetNumProperty("PointerID",2);
  194.             m_lgauge2->SetFloatProperty("PointerValue",a * b);
  195.             break;
  196.         case 1:
  197.             m_lgauge2->SetNumProperty("PointerID",0);
  198.             a = m_lgauge2->GetFloatProperty("PointerValue");
  199.             
  200.             m_lgauge2->SetNumProperty("PointerID",1);
  201.             b = m_lgauge2->GetFloatProperty("PointerValue");
  202.             
  203.             m_lgauge2->SetNumProperty("PointerID",2);
  204.             m_lgauge2->SetFloatProperty("PointerValue",a * b);
  205.             break;
  206.         case 2:
  207.             m_lgauge2->SetNumProperty("PointerID",2);
  208.             a = m_lgauge2->GetFloatProperty("PointerValue");
  209.             b=(float) pow((double) a,0.5);
  210.             
  211.             m_lgauge2->SetNumProperty("PointerID",0);
  212.             m_lgauge2->SetFloatProperty("PointerValue",b);
  213.             
  214.             m_lgauge2->SetNumProperty("PointerID",1);
  215.             m_lgauge2->SetFloatProperty("PointerValue",b);
  216.             break;
  217.         }
  218.     
  219. }
  220.  
  221. void CVcView::OnChangeLgauge3(UINT, int, CWnd*, LPVOID)
  222. {
  223. int pointerid;
  224. float b,pstart,pstop;
  225.  
  226.     pointerid = (int) m_lgauge3->GetNumProperty("PointerID");
  227.     
  228.     switch (pointerid) {
  229.         case 0:
  230.             m_lgauge3->SetNumProperty("PointerID",0);
  231.             pstart = m_lgauge3->GetFloatProperty("PointerStart");
  232.             pstop = m_lgauge3->GetFloatProperty("PointerStop");
  233.             
  234.             m_lgauge3->SetNumProperty("PointerID",1);
  235.             m_lgauge3->SetFloatProperty("PointerValue",pstart);
  236.             
  237.             m_lgauge3->SetNumProperty("PointerID",2);
  238.             m_lgauge3->SetFloatProperty("PointerValue",pstop);
  239.             break;
  240.         case 1:
  241.             m_lgauge3->SetNumProperty("PointerID",1);
  242.             pstart = m_lgauge3->GetFloatProperty("PointerValue");
  243.             
  244.             m_lgauge3->SetNumProperty("PointerID",0);
  245.             b = m_lgauge3->GetFloatProperty("PointerStop");
  246.             if (pstart > b-5) 
  247.                 pstart = b-5;
  248.             
  249.             m_lgauge3->SetFloatProperty("PointerStart",pstart);
  250.             m_lgauge3->SetNumProperty("PointerID",1);
  251.             m_lgauge3->SetFloatProperty("PointerValue",pstart);
  252.             break;
  253.         case 2:
  254.             m_lgauge3->SetNumProperty("PointerID",2);
  255.             pstop = m_lgauge3->GetFloatProperty("PointerValue");
  256.             
  257.             m_lgauge3->SetNumProperty("PointerID",0);
  258.             b = m_lgauge3->GetFloatProperty("PointerStart");
  259.             if (pstop < b+5) 
  260.                 pstop = b+5;
  261.             
  262.             m_lgauge3->SetFloatProperty("PointerStop",pstop);
  263.             m_lgauge3->SetNumProperty("PointerID",2);
  264.             m_lgauge3->SetFloatProperty("PointerValue",pstop);
  265.             break;
  266.         }
  267. }
  268.  
  269.